package com.by.auto;

import com.auth0.jwt.JWT;
import com.by.token.TokenTemplate;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;

/**
 * @author 江俊俊
 * @version 1.0
 * @description
 * @date 2025/2/12 17:40
 * @since JDK1.8
 */
@AutoConfiguration
@ConditionalOnClass({JWT.class})
@ConditionalOnProperty(prefix = "token", name = "enabled", matchIfMissing = true)//
@EnableConfigurationProperties(value = {TokenProperties.class})
public class TokenAutoConfigure {

    @Bean
    @ConditionalOnMissingBean(value = {TokenTemplate.class})
    public TokenTemplate tokenTemplate(TokenProperties properties) {

        TokenTemplate tokenTemplate = new TokenTemplate(properties);
        return tokenTemplate;
    }
}
